#!/bin/bash
if [[ "up" == $1 ]]; then
  #添加bridge
  sudo brctl addbr br0
  #将br0和主机网卡绑定起来（可能让网络断掉，最好在本机操作，不要通过网络）
  # replace eno1 to enp0s3
  sudo brctl addif br0 enp0s3
  #将br0设置为启用STP协议
  sudo brctl stp br0 on
  #将主机网卡的IP设置为0
  sudo ifconfig enp0s3 0
  #将br0网络配置好
  sudo dhclient br0
  exit 0
elif [[ "down" == $1 ]]; then
  sudo ifconfig br0 down
  sudo brctl delbr br0
  sudo ifconfig enp0s3 down
  sudo ifconfig enp0s3 up
  sudo /etc/init.d/networking restart
  exit 0
else
  echo "error: no interface specified"
  exit 1
fi
